home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CBGRX100.ARJ / DUMPTEXT.C < prev    next >
Text File  |  1992-04-10  |  5KB  |  175 lines

  1. /** 
  2.  ** DUMPTEXT.C 
  3.  **
  4.  **  Copyright (C) 1992, Csaba Biegl
  5.  **    820 Stirrup Dr, Nashville, TN, 37221
  6.  **    csaba@vuse.vanderbilt.edu
  7.  **
  8.  **  This file is distributed under the terms listed in the document
  9.  **  "copying.cb", available from the author at the address above.
  10.  **  A copy of "copying.cb" should accompany this file; if not, a copy
  11.  **  should be available from where this file was obtained.  This file
  12.  **  may not be distributed without a verbatim copy of "copying.cb".
  13.  **  You should also have received a copy of the GNU General Public
  14.  **  License along with this program (it is in the file "copying");
  15.  **  if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  16.  **  Cambridge, MA 02139, USA.
  17.  **
  18.  **  This program is distributed in the hope that it will be useful,
  19.  **  but WITHOUT ANY WARRANTY; without even the implied warranty of
  20.  **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21.  **  GNU General Public License for more details.
  22.  **/
  23.  
  24. #include "grx.h"
  25. #include "libgrx.h"
  26. #include "grxfont.h"
  27. #include "clipping.h"
  28.  
  29. #define  FAST    0x04
  30.  
  31. void GrDumpText(int col,int row,int wdt,int hgt,GrTextRegion *r)
  32. {
  33.     GrFont *f = CHECK_FONT(r->txr_font);
  34.     GrColorTableP fgcp,bgcp;
  35.     char *ptr,*bpt;
  36.     int xtmp,ytmp;
  37.     int xpos,ypos;
  38.     int chrw,chrh;
  39.     int fgc,bgc;
  40.     int offs,size;
  41.     int minc,maxc;
  42.     int type,attr;
  43.     int xchr,chr;
  44.     int chrsize;
  45.     int fast;
  46.     MOUSE_FLAG;
  47.  
  48.     if((f == NULL) || !f->fnt_isfixed) return;
  49.     if((col >= r->txr_width) || (row >= r->txr_height)) return;
  50.     if(col < 0) { wdt += col; col = 0; }
  51.     if(row < 0) { hgt += row; row = 0; }
  52.     if(wdt > (r->txr_width  - col)) wdt = r->txr_width  - col;
  53.     if(hgt > (r->txr_height - row)) hgt = r->txr_height - col;
  54.     if((wdt <= 0) || (hgt <= 0)) return;
  55.     chrw = f->fnt_width;
  56.     chrh = f->fnt_height;
  57.     xpos = r->txr_xpos + (chrw * col);
  58.     ypos = r->txr_ypos + (chrh * row);
  59.     xtmp = xpos + (chrw * wdt) - 1;
  60.     ytmp = ypos + (chrh * hgt) - 1;
  61.     if((xpos > _GrHiX) || (xtmp <= _GrLoX)) return;
  62.     if((ypos > _GrHiY) || (ytmp <= _GrLoY)) return;
  63.     while(xpos < _GrLoX) { if(--wdt == 0) return; xpos += chrw; col++; }
  64.     while(ypos < _GrLoY) { if(--hgt == 0) return; ypos += chrh; row++; }
  65.     while(xtmp > _GrHiX) { if(--wdt == 0) return; xtmp -= chrw; }
  66.     while(ytmp > _GrHiY) { if(--hgt == 0) return; ytmp -= chrh; }
  67.     type = r->txr_chrtype;
  68.     fast = (r->txr_backup != NULL) ? FAST : 0;
  69.     switch(type | fast) {
  70.       case GR_WORD_TEXT:
  71.       case GR_WORD_TEXT | FAST:
  72.         size = sizeof(short);
  73.         fgc  = r->txr_fgcolor.v;
  74.         bgc  = r->txr_bgcolor.v;
  75.         break;
  76.       case GR_ATTR_TEXT:
  77.       case GR_ATTR_TEXT | FAST:
  78.         attr = (-1);
  79.         size = sizeof(short);
  80.         fgcp = r->txr_fgcolor.p;
  81.         bgcp = r->txr_bgcolor.p;
  82.         break;
  83.       default:
  84.         size = sizeof(char);
  85.         fgc  = r->txr_fgcolor.v;
  86.         bgc  = r->txr_bgcolor.v;
  87.         break;
  88.     }
  89.     offs = (row * r->txr_lineoffset) + (col * size);
  90.     ptr  = r->txr_buffer + offs;
  91.     bpt  = r->txr_backup + offs;
  92.     offs = r->txr_lineoffset - (wdt * size);
  93.     minc = f->fnt_minchar;
  94.     maxc = f->fnt_maxchar;
  95.     chrsize = FFP(f)->ff_chrsize;
  96.     MOUSE_BLOCK(CURC,
  97.         xpos,ypos,
  98.         (xpos + (chrw * wdt) - 1),
  99.         (ypos + (chrh * hgt) - 1)
  100.     );
  101.     for( ; --hgt >= 0; ypos += chrh,ptr += offs,bpt += offs) {
  102.         xtmp = xpos;
  103.         ytmp = wdt;
  104.         for( ; --ytmp >= 0; xtmp += chrw,ptr += size,bpt += size) {
  105.         switch(type | fast) {
  106.           case GR_WORD_TEXT | FAST:
  107.           case GR_WORD_TEXT:
  108.             chr = *((unsigned short *)ptr);
  109.             if(!fast) break;
  110.             if(chr == *((unsigned short *)bpt)) continue;
  111.             *((unsigned short *)bpt) = chr;
  112.             if(chr == ' ') chr = (-1);
  113.             break;
  114.           case GR_ATTR_TEXT | FAST:
  115.           case GR_ATTR_TEXT:
  116.             xchr = *((unsigned short *)ptr);
  117.             if(fast && (xchr == *((unsigned short *)bpt))) continue;
  118.             chr = xchr & 0xff;
  119.             if(attr != (xchr &= 0xff00)) {
  120.             fgc  = (xchr >> 8)  & 0x0f;
  121.             bgc  = (xchr >> 12) & 0x07;
  122.             fgc  = GR_CTABLE_COLOR(fgcp,fgc);
  123.             bgc  = GR_CTABLE_COLOR(bgcp,bgc);
  124.             attr = xchr;
  125.             }
  126.             if(fast && (chr == ' ')) chr = (-1);
  127.             break;
  128.           default:
  129.             chr = *((unsigned char *)ptr);
  130.             if(!fast) break;
  131.             if(chr == *((unsigned char *)bpt)) continue;
  132.             *((unsigned char *)bpt) = chr;
  133.             if(chr == ' ') chr = (-1);
  134.             break;
  135.         }
  136.         if((chr > maxc) || ((chr -= minc) < 0)) {
  137.             _GrSetPixBlock(PIXEL_ADDR(xtmp,ypos),bgc,chrw,chrh);
  138.             continue;
  139.         }
  140.         _GrDrawChar(PIXEL_ADDR(xtmp,ypos),
  141.             chrw,chrh,
  142.             FFP(f)->ff_bits + (chr * chrsize),
  143.             fgc,bgc
  144.         );
  145.         }
  146.     }
  147.     MOUSE_UNBLOCK();
  148. }
  149.  
  150. void GrDumpTextRegion(GrTextRegion *r)
  151. {
  152.     GrDumpText(0,0,r->txr_width,r->txr_height,r);
  153. }
  154.  
  155. void GrDumpChar(int chr,int col,int row,GrTextRegion *r)
  156. {
  157.     register int offs;
  158.  
  159.     if((col < 0) || (col >= r->txr_width))  return;
  160.     if((row < 0) || (row >= r->txr_height)) return;
  161.     switch(r->txr_chrtype) {
  162.       case GR_WORD_TEXT:
  163.       case GR_ATTR_TEXT:
  164.         offs = (row * r->txr_lineoffset) + (col * sizeof(short));
  165.         *((short *)(r->txr_buffer + offs)) = chr;
  166.         break;
  167.       default:
  168.         offs = (row * r->txr_lineoffset) + (col * sizeof(char));
  169.         *((char *)(r->txr_buffer + offs)) = chr;
  170.         break;
  171.     }
  172.     GrDumpText(col,row,1,1,r);
  173. }
  174.  
  175.